import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter_popcorntime/config/application.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';

class CachedImageWidget extends StatelessWidget {
  final String imageUrl;
  final BoxFit fit;

  const CachedImageWidget({required this.imageUrl, required this.fit});

  @override
  Widget build(BuildContext context) {
    try {
      return CachedNetworkImage(
        cacheManager: Application.cacheManager,
        fit: BoxFit.fitWidth,
        imageUrl: imageUrl,
        placeholder: (context, url) =>
            SpinKitFadingFour(color: Colors.lightBlue),
        errorWidget: (context, url, error) => Image.asset(
            "assets/images/icon_posterholder.png",
            fit: BoxFit.contain),
      );
    } catch (e) {
      print("$e");
      return Container();
    }
  }
}
